# -*- coding:utf-8 -*-
'''

Request URL:https://m.weibo.cn/api/container/getIndex?uid=1350995007&luicode=10000011&lfid=100103type%3D3%26q%3D%E5%8F%A4%E5%8A%9B%E5%A8%9C%E6%89%8E&featurecode=20000320&type=uid&value=1350995007&containerid=1005051350995007

https://m.weibo.cn/p/100103type%3D3%26q%3DAcarat?type=user&queryVal=Acarat&featurecode=20000320&luicode=10000011&lfid=106003type%3D1&title=Acarat

'''



import requests
from time import sleep
import jieba.analyse
from html2text import html2text
from PIL import Image, ImageSequence
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud, ImageColorGenerator

def GetUIDFromScreenName(name):

     ##################################################################
     # url中存在100103type=3q={} ,直接不能够将'type=3q='进行字符串替换
     # 解决办法： 直接用编码之后的字符串替换，固定值 100103type%3D3%26q%3D
     ##################################################################

     result = requests.get('https://m.weibo.cn/api/container/getIndex?type=user&queryVal={}&lfid=100103type%3D3%26q%3D{}&title={}&containerid=100103type%3D3%26q%3D{}'.format(name, name, name, name))
     json_data = result.json() # get data

     #################################################################
     # me = json_data['cards'][1]
     # info = me['card_group']
     # print info[0]['user']
     #################################################################
     person_info = json_data['cards'][1]['card_group'][0]['user']
     print person_info['id']
     print person_info['screen_name']
     uid = person_info['id']
     return uid

# uid 是用户ID
def GetPersonInfoFromScreenName(name):

     ##################################################################
     # url中存在100103type=3q={} ,直接不能够将'type=3q='进行字符串替换
     # 解决办法： 直接用编码之后的字符串替换，固定值 100103type%3D3%26q%3D
     ##################################################################

     result = requests.get('https://m.weibo.cn/api/container/getIndex?type=user&queryVal={}&lfid=100103type%3D3%26q%3D{}&title={}&containerid=100103type%3D3%26q%3D{}'.format(name, name, name, name))
     json_data = result.json() # get data

     #################################################################
     # me = json_data['cards'][1]
     # info = me['card_group']
     # print info[0]['user']
     #################################################################
     person_info = json_data['cards'][1]['card_group'][0]['user']
     print person_info['id']
     print person_info['screen_name']
     uid = person_info['id']
     return person_info